package com.yserp.project.erp.store.instorelog.controller;

import com.yserp.common.utils.poi.ExcelUtil;
import com.yserp.framework.aspectj.lang.annotation.Log;
import com.yserp.framework.aspectj.lang.enums.BusinessType;
import com.yserp.framework.web.controller.BaseController;
import com.yserp.framework.web.domain.AjaxResult;
import com.yserp.framework.web.page.TableDataInfo;
import com.yserp.project.erp.store.instorelog.domain.StockInLog;
import com.yserp.project.erp.store.instorelog.service.IStockInLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 入库日志Controller
 * 
 * @author yserp
 * @date 2022-07-08
 */
@Controller
@RequestMapping("/store/instorelog")
public class StockInLogController extends BaseController
{
    private String prefix = "erp/store/instorelog";

    @Autowired
    private IStockInLogService stockInLogService;

    @RequiresPermissions("store:instorelog:view")
    @GetMapping()
    public String instorelog()
    {
        return prefix + "/instorelog";
    }

    /**
     * 查询入库日志列表
     */
    @RequiresPermissions("store:instorelog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StockInLog stockInLog)
    {
        startPage();
        List<StockInLog> list = stockInLogService.selectStockInLogList(stockInLog);
        return getDataTable(list);
    }

    /**
     * 导出入库日志列表
     */
    @RequiresPermissions("store:instorelog:export")
    @Log(title = "入库日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StockInLog stockInLog)
    {
        List<StockInLog> list = stockInLogService.selectStockInLogList(stockInLog);
        ExcelUtil<StockInLog> util = new ExcelUtil<StockInLog>(StockInLog.class);
        return util.exportExcel(list, "入库日志数据");
    }

    /**
     * 新增入库日志
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存入库日志
     */
    @RequiresPermissions("store:instorelog:add")
    @Log(title = "入库日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StockInLog stockInLog)
    {
        return toAjax(stockInLogService.insertStockInLog(stockInLog));
    }

    /**
     * 修改入库日志
     */
    @RequiresPermissions("store:instorelog:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        StockInLog stockInLog = stockInLogService.selectStockInLogById(id);
        mmap.put("stockInLog", stockInLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存入库日志
     */
    @RequiresPermissions("store:instorelog:edit")
    @Log(title = "入库日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StockInLog stockInLog)
    {
        return toAjax(stockInLogService.updateStockInLog(stockInLog));
    }

    /**
     * 删除入库日志
     */
    @RequiresPermissions("store:instorelog:remove")
    @Log(title = "入库日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stockInLogService.deleteStockInLogByIds(ids));
    }
}
